﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Traceability.App.Instructure
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private readonly TraceabilityDbContext db;

        public BaseRepository(TraceabilityDbContext db) 
        {
            this.db = db;
        }
        public int Add(T t)
        {
            db.Set<T>().Add(t);
            return db.SaveChanges();
        }

        public int Delete(T t)
        {
            db.Set<T>().Remove(t);
            return db.SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>();
        }

        public T GetValue(int id)
        {
            return db.Set<T>().Find(id);
        }

       

        public int Update(T t)
        {
            db.Set<T>().Update(t);
            return db.SaveChanges();
        }

        public int UpdateAll(List<T> t)
        {
            db.Set<T>().UpdateRange(t);
            return db.SaveChanges();
        }
    }
}
